<?php

/* * 
 * 职位模型
 */
namespace Common\Model;
use Common\Model\CommonModel;



class ProductModel extends CommonModel {


     
    public function get_list($data){





    	$cache = ( int ) $data [cache];
    	
    
    	$limit = $data ['limit']?$data ['limit']:0;
    
    	$num = $data ['num'] ? $data ['num'] : 20;
    	
    	$where ['status'] = array ("EQ",1 	);
		$where ['kucun'] = array ("gt",0 	);
    	if (isset ( $data ['where'] ) && $s=$data ['where']) {
    	$where['_complex'] = $s;
    		
    	}
    	$order = empty ( $data ['order'] ) ? "top DESC,listorder DESC,id desc" : $data ['order'];

    	if ($cache) {
    		$result = $this->field('content',true)->cache ( true, $cache )->where ( $where )->limit ( $limit,$num )->order ( $order )->select ();
    	} else {
    		$result = $this->field('content',true)->where ( $where )->limit ( $limit,$num )->order ( $order )->select ();
    	}



		$WX_ZK=C("WX_ZK");
		$QB_ZK=C("QB_ZK");


		foreach($result as $k=>$v){






			$v[url]=U('Product/show',array("id"=>$v["id"]));


			$return[]=$v;

		}




    	
    	return $return;
    	
    	
    	
    	
    }
    
    function get_one($id){
    	


		$p_p=D("Product")->where(array("id"=>$id))->find();

		if($p_p["thumbs"]){
			$p_p["thumbs"]=array_merge(explode(",",$p_p["thumb"]),explode(",",$p_p["thumbs"]));
		}else{
			$p_p["thumbs"]=explode(",",$p_p["thumb"]);
		}


		$p_p[danjia]=round($p_p["price"]/$p_p["danjia_num"],2);
		$p_p[qb_danjia]=round($p_p["qb_price"]/$p_p["danjia_num"],2);



		$p_p[url]=U('Product/show',array("id"=>$p_p["id"]));


    	return  $p_p;
    	
    	
    	
    	
    	
    }
    function get_sum(){



		$cart_list = unserialize ( cookie ( "product_cart" ) );


		$y_price=0;
		$z_num=0;
		$qb_price=0;

		foreach ($cart_list as $k=>$v){

			$s=D("Product")->get_one($v["id"]);




			$s["num"]=$v["num"];





			$y_price+=$s["num"]*$s["price"];
			$qb_price+=$s["num"]*$s["qb_price"];

			$z_num+=$v["num"];

			$cartlist[]=$s;


		}





		return  array(
			"data"=>$cartlist,
			"price_sum"=>$y_price,
			"qb_price_sum"=>$qb_price,
			"num"=>$z_num,
		);





	}


	function  jiancha(){



		$ss=false;
		$cart_list = unserialize ( cookie ( "product_order_cart" ) );


		foreach($cart_list as $v){

			$prduct_id=D("ProductList")->where(array("id"=>$v["id"]))->getField("product_id");

			$s=D("Product")->where(array("id"=>$prduct_id))->getField("kucun");
			$st=D("Product")->where(array("id"=>$prduct_id))->getField("status");




			if(!$s||!$st){

				$ss=true;


				unset($cart_list[$v["id"]]);


				cookie ( "product_order_cart", serialize ( $cart_list ) ,86400);



			}



		}


		return $ss;

	}


	function get_order_sum(){


		$cart_list = unserialize ( cookie ( "product_order_cart" ) );


		$y_price=0;
		$z_num=0;
		$qb_price;
		foreach ($cart_list as $k=>$v){

			$s=D("Product")->get_one($v["id"]);




			$s["num"]=$v["num"];




			$y_price+=$s["num"]*$s["price"];
			$qb_price+=$s["num"]*$s["qb_price"];

			$z_num+=$v["num"];

			$cartlist[]=$s;


		}

		if(count($cartlist)>1){


			$title=$cartlist[0]["d_title"];

		}else{
			$title=$cartlist[0]["d_title"]."等";
		}





		return  array(
			"data"=>$cartlist,
			"price_sum"=>$y_price,
			"qb_price_sum"=>$qb_price,
			"num"=>$z_num,
			"title"=>$title
		);





	}

    

    
    
 
    
    

	}

?>